package com.leilei;

import lombok.Data;

import java.util.Objects;

/**
 * @author shuiyun
 * @program collectDemo
 * @description 节点
 * @date 2023-02-23 16:07
 **/
@Data
public class Node<T> {


    private Node<T> pre;

    private Node<T> next;

    private T data;

    public Node(T t) {
        this.data = t;
    }

    public Node(Node<T> pre, T t, Node<T> next) {
        this.pre = pre;
        this.data = t;
        this.next = next;
    }

    /**
     * 清空节点
     *
     * @author shuiyun
     * @date 2023-02-23 16:31
     */
    public void clear() {
        this.pre = null;
        this.next = null;
        this.data = null;
    }

    @Override
    public String toString() {
        String preData = pre == null ? "null" : pre.getData().toString();
        String nexData = next == null ? "null" : next.getData().toString();
        return "Node{" +
                "pre=" + preData +
                ", data=" + data +
                ", next=" + nexData +
                '}';
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        Node<?> node = (Node<?>) o;
        return Objects.equals(data, node.data);
    }

    @Override
    public int hashCode() {
        return Objects.hash(data);
    }
}
